package com.ouc.dataMange.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ouc.common.utils.file.FileUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ouc.common.annotation.Log;
import com.ouc.common.core.controller.BaseController;
import com.ouc.common.core.domain.AjaxResult;
import com.ouc.common.enums.BusinessType;
import com.ouc.dataMange.domain.SysDataShipPath;
import com.ouc.dataMange.service.ISysDataShipPathService;
import com.ouc.common.utils.poi.ExcelUtil;
import com.ouc.common.core.page.TableDataInfo;

/**
 * shipPathController
 *
 * @author ouc
 * @date 2025-08-05
 */
@RestController
@RequestMapping("/dataMange/shipPath")
public class SysDataShipPathController extends BaseController {
  @Autowired
  private ISysDataShipPathService sysDataShipPathService;

  /**
   * 查询shipPath列表
   */
//    @PreAuthorize("@ss.hasPermi('dataMange:shipPath:list')")
  @GetMapping("/list")
  public TableDataInfo list(SysDataShipPath sysDataShipPath) {
    startPage();
    List<SysDataShipPath> list = sysDataShipPathService.selectSysDataShipPathList(sysDataShipPath);
    for (SysDataShipPath shipPath : list) {
      shipPath.setShipPathName(FileUtils.getName(shipPath.getPathFilePath()));
    }
    return getDataTable(list);
  }

  /**
   * 导出shipPath列表
   */
  @PreAuthorize("@ss.hasPermi('dataMange:shipPath:export')")
  @Log(title = "shipPath", businessType = BusinessType.EXPORT)
  @GetMapping("/export")
  public void export(HttpServletResponse response, SysDataShipPath sysDataShipPath) {
    List<SysDataShipPath> list = sysDataShipPathService.selectSysDataShipPathList(sysDataShipPath);
    ExcelUtil<SysDataShipPath> util = new ExcelUtil<SysDataShipPath>(SysDataShipPath.class);
    util.exportExcel(response, list, "历史航线数据");
  }

  /**
   * 获取shipPath详细信息
   */
  @PreAuthorize("@ss.hasPermi('dataMange:shipPath:query')")
  @GetMapping(value = "/{pathId}")
  public AjaxResult getInfo(@PathVariable("pathId") Integer pathId) {
    return success(sysDataShipPathService.selectSysDataShipPathByPathId(pathId));
  }

  /**
   * 新增shipPath
   */
  @PreAuthorize("@ss.hasPermi('dataMange:shipPath:add')")
  @Log(title = "shipPath", businessType = BusinessType.INSERT)
  @PostMapping
  public AjaxResult add(@RequestBody SysDataShipPath sysDataShipPath) {
    return toAjax(sysDataShipPathService.insertSysDataShipPath(sysDataShipPath));
  }

  /**
   * 修改shipPath
   */
  @PreAuthorize("@ss.hasPermi('dataMange:shipPath:edit')")
  @Log(title = "shipPath", businessType = BusinessType.UPDATE)
  @PutMapping
  public AjaxResult edit(@RequestBody SysDataShipPath sysDataShipPath) {
    return toAjax(sysDataShipPathService.updateSysDataShipPath(sysDataShipPath));
  }

  /**
   * 删除shipPath
   */
  @PreAuthorize("@ss.hasPermi('dataMange:shipPath:remove')")
  @Log(title = "shipPath", businessType = BusinessType.DELETE)
  @DeleteMapping("/{pathIds}")
  public AjaxResult remove(@PathVariable Integer[] pathIds) {
    return toAjax(sysDataShipPathService.deleteSysDataShipPathByPathIds(pathIds));
  }
}
